﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using RouterControl.Whs.SingletonService;

namespace RouterControl.WhsAddIn.SettingsControls
{
    public partial class EnablePortForwarding : SettingsControlBase
    {
        public EnablePortForwarding(RouterControlSettingsTab2 tab)
			: base(tab)
		{
			InitializeComponent();

			this.lineBox.Header.Text = Properties.Resources.txtSettingPortForwarding;
		}

        private void OnCheckedChanged(object sender, EventArgs e)
        {
            // any change?
            if ((this.enablePortForwardingCB.Checked == ((_tab.Settings.EnablePortForwardingMonitoring & ExtendedEnabled.Enabled) == ExtendedEnabled.Enabled)) &&
                (this.enableNotificationsCB.Checked == (_tab.Settings.EnablePortForwardingMonitoring == ExtendedEnabled.EnabledWithNotifications)))
                return;

            // save settings
            if (this.enablePortForwardingCB.Checked)
            {
                if (this.enableNotificationsCB.Checked)
                {
                    _tab.Settings.EnablePortForwardingMonitoring = ExtendedEnabled.EnabledWithNotifications;
                }
                else
                {
                    _tab.Settings.EnablePortForwardingMonitoring = ExtendedEnabled.Enabled;
                }
            }
            else
            {
                _tab.Settings.EnablePortForwardingMonitoring = ExtendedEnabled.Disabled;
            }

            _tab.Services.EnableSettingsApply();

            // handle status
            this.enableNotificationsCB.Enabled = this.enablePortForwardingCB.Checked;
        }

        private void EnablePortForwarding_Load(object sender, EventArgs e)
        {
            // load settings
            this.enablePortForwardingCB.Checked = ((_tab.Settings.EnablePortForwardingMonitoring & ExtendedEnabled.Enabled) == ExtendedEnabled.Enabled);
            this.enableNotificationsCB.Checked = (_tab.Settings.EnablePortForwardingMonitoring == ExtendedEnabled.EnabledWithNotifications);
            this.enableNotificationsCB.Enabled = this.enablePortForwardingCB.Checked;

            // register events
            this.enablePortForwardingCB.CheckedChanged += new EventHandler(OnCheckedChanged);
            this.enableNotificationsCB.CheckedChanged += new EventHandler(OnCheckedChanged);
        }
    }
}
